package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Order;
import com.itheima.service.OrderService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Reference
    private OrderService orderService;

    /**
     * 分页查询
     * @param queryPageBean
     * @return
     */
    @RequestMapping("/findOrdersPage")
    public Result findOrdersPage(@RequestBody QueryPageBean queryPageBean){
        try {
            PageResult result =  orderService.findOrdersPage(queryPageBean);
            return new Result(true, MessageConstant.GET_ORDERSETTINGLIST_SUCCESS,result);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.GET_ORDERSETTINGLIST_SUCCESS);
        }

    }

    /**
     * 后台预约
     * @return
     */
    @RequestMapping("/add")
    public Result add(Integer[] setmealIds,@RequestBody Map map){
        Result result=null;
        try {
             result=orderService.addOrder(setmealIds,map);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return  result;
    }

    /**
     * 确认预约
     * @return
     */
    @RequestMapping("/confirm")
    public void confirm(Integer id){

        try {
            orderService.confirm(id, Order.ORDERSTATUS_YES);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 取消预约
     */
    @RequestMapping("/delete")
    public void delete(Integer id){
        try {
            orderService.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
